<!--
 - MineAdmin is committed to providing solutions for quickly building web applications
 - Please view the LICENSE file that was distributed with this source code,
 - For the full copyright and license information.
 - Thank you very much for using MineAdmin.
 -
 - @Author X.Mo<root@imoi.cn>
 - @Link   https://gitee.com/xmo/mineadmin-vue
-->
<template>
  <a-modal v-model:visible="visible" fullscreen :footer="false">
    <!-- CRUD 组件 -->
    <ma-crud :options="crud" :columns="columns" ref="crudRef">
      <template #create_time="{ record }">
        {{ tool.dateFormat(record.create_time, 'yyyy-MM-dd hh:mm:ss', '-') }}
      </template>
    </ma-crud>
  </a-modal>
</template>

<script setup>
import { ref, reactive } from 'vue'

import { Message } from '@arco-design/web-vue'
import paymentMember from '@/api/payment/paymentMember'
import tool from "@/utils/tool.js";
const crudRef = ref()
const visible = ref(false)
const currentRow = ref({ id: undefined, name: undefined })

const changeStatus = async (status, id) => {
  const response = await paymentMember.changeStatus({ id, status })
  if (response.success) {
    Message.success(response.message)
  }
}

const open = (row) => {
  currentRow.value = row
  crudRef.value.requestData()
  visible.value = true
}

const crud = reactive({
  autoRequest: false,
  api: paymentMember.getList,
  recycleApi: paymentMember.getRecycleList,
  showIndex: false,
  pageLayout: 'fixed',
  rowSelection: { showCheckedAll: true },
  operationColumn: true,
  operationColumnWidth: 300,
  add: { show: true, api: paymentMember.save, auth: ['payment:member:save'] },
  edit: { show: true, api: paymentMember.update, auth: ['payment:member:update'] },
  delete: {
    show: true,
    api: paymentMember.deletes, auth: ['payment:member:delete'],
    realApi: paymentMember.realDeletes, realAuth: ['payment:member:realDeletes']
  },
  recovery: { show: true, api: paymentMember.recoverys, auth: ['payment:member:recovery'] },
  formOption: { width: '800px' },
  beforeAdd: (form) => form.method_id = currentRow.value.id,
  beforeRequest: (params) => {
    params.method_id = currentRow.value.id
  },
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },

  {
    title: "钻石",
    dataIndex: "diamond",
    formType: "input-number",
    commonRules: {
      required: true,
      message: "请输入钻石数量"
    },
    precision: 2
  },
  {
    title: "支付价格",
    dataIndex: "money",
    formType: "input-number",
    commonRules: {
      required: true,
      message: "请输入价格"
    },
    precision: 2
  },

  {
    title: "排序",
    dataIndex: "sort",
    formType: "input-number",
    commonRules: {
      required: true,
      message: "请输入排序"
    }
  },


  {
    title: "状态",
    dataIndex: "status",
    formType: "radio",
    search: true,
    commonRules: {
      required: true,
      message: "请输入状态"
    },
    dict: {
      name: "data_status",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    },
    addDefaultValue: 1
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    width:180,
    formType: "range",
    search: false,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  }
])

defineExpose({ open })
</script>

<style scoped>
</style>